package com.zch.file;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;

public class ObjectInputStream01 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        // 1.创建流对象
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("d:\\data.dat"));
        // 2.读取，注意读取(反序列化)顺序应与保存数据(序列化)的顺序一致，否则会出现异常
        System.out.println(ois.readInt());
        System.out.println(ois.readBoolean());
        System.out.println(ois.readChar());
        System.out.println(ois.readDouble());
        System.out.println(ois.readUTF());
        System.out.println(ois.readObject());
        // 3.关闭外层流即可，底层会关闭内层流
        ois.close();
        System.out.println("以反序列化的方式读取(恢复)ok~");
    }
}
